package com.xdb.logging;

public class Log4jImpl implements Logger {

	private static final String callerFQCN = Log4jImpl.class.getName();

	private org.apache.log4j.Logger log;

	private int errorCount;
	private int warnCount;
	private int infoCount;
	private int debugCount;

	public Log4jImpl(org.apache.log4j.Logger log) {
		this.log = log;
	}

	public Log4jImpl(String name) {
		log = org.apache.log4j.Logger.getLogger(name);
	}

	public org.apache.log4j.Logger getLog() {
		return log;
	}

	public boolean isDebugEnabled() {
		return log.isDebugEnabled();
	}

	public void error(Object s, Throwable e) {
		errorCount++;
		log.log(callerFQCN, org.apache.log4j.Level.ERROR, s, e);
	}

	public void error(Object s) {
		errorCount++;
		log.log(callerFQCN, org.apache.log4j.Level.ERROR, s, null);
	}

	public void debug(Object s) {
		debugCount++;
		log.log(callerFQCN, org.apache.log4j.Level.DEBUG, s, null);
	}

	public void debug(Object s, Throwable e) {
		debugCount++;
		log.log(callerFQCN, org.apache.log4j.Level.DEBUG, s, e);
	}

	public void warn(Object s) {
		log.log(callerFQCN, org.apache.log4j.Level.WARN, s, null);
		warnCount++;
	}

	public void warn(Object s, Throwable e) {
		log.log(callerFQCN, org.apache.log4j.Level.WARN, s, e);
		warnCount++;
	}

	public int getWarnCount() {
		return warnCount;
	}

	public int getErrorCount() {
		return errorCount;
	}

	public void resetStat() {
		errorCount = 0;
		warnCount = 0;
		infoCount = 0;
		debugCount = 0;
	}

	public int getDebugCount() {
		return debugCount;
	}

	public boolean isInfoEnabled() {
		return log.isInfoEnabled();
	}

	public void info(Object msg) {
		infoCount++;
		log.log(callerFQCN, org.apache.log4j.Level.INFO, msg, null);
	}

	public boolean isWarnEnabled() {
		return log.isEnabledFor(org.apache.log4j.Level.WARN);
	}

	public int getInfoCount() {
		return infoCount;
	}

	public String toString() {
		return log.toString();
	}
}
